import { getGoodsRead } from '@/service/api/product'
import { cloneDeep } from 'lodash'
import { useProductStore } from '@/store/modules/product'
import { storeToRefs } from 'pinia'

const productStore = useProductStore()
const { specificationData } = storeToRefs(productStore)

export const useGetGoodsInfo = async (goodsId: number) => {
  try {
    const { data } = await getGoodsRead(goodsId)
    console.log('data', data)
    if (data) {
      const { id, sku_value, goodsSkus, goodsSkusCard, sku_type } = data
      specificationData.value = {
        id,
        sku_type: sku_type || 0,
        sku_value: sku_value,
        goodsSkus: goodsSkus,
      }
      console.log('specificationData', specificationData.value)
      const singleSkuValue = cloneDeep(specificationData.value.sku_value)
      const goodsSkusCardList = cloneDeep(goodsSkusCard)
      return { singleSkuValue, goodsSkusCardList }
    }
  } catch (error) {
    console.error(error)
    return null
  }
}
